# !/usr/usuari/des python
#  -*- coding: utf-8 -*-

"""
@Author        : itgnay
@Time          : 2023/3/3 15:43
@FileName      : 线性dp.py
@LastEditors   : None
@Editors       : PyCharm
"""

dp = [0] * 20018
w = [0] * 40
V = int(input())
n = int(input())
for i in range(1, n + 1): w[i] = int(input())
for i in range(1, n + 1):
    for j in range(V, -1, -1):
        dp[i] = max(dp[i], dp[i - w[i]] + w[i])
print(dp[n])
